package com.voute.Presenter.Impl;

import com.voute.Model.Bean.BaseBean;
import com.voute.Model.Bean.SubCommentsBean;
import com.voute.Model.ISubCommentsModel;
import com.voute.Model.Impl.SubCommentsModelImpl;
import com.voute.Presenter.ISubCommentsPresenter;
import com.voute.Utils.CommonSubscriber;
import com.voute.Utils.TransformUtils;
import com.voute.View.IView.ISubCommentsView;

/**
 * Created by liucxu on 2017/1/25.
 */

public class SubCommentsPresenterImpl implements ISubCommentsPresenter {
    private ISubCommentsView sub_comments_view;
    private ISubCommentsModel model;

    public SubCommentsPresenterImpl(ISubCommentsView view) {
        sub_comments_view = view;
        model = new SubCommentsModelImpl();
    }

    @Override
    public void getComments(String fid, String anchor) {
        sub_comments_view.showLoading();
        model.getComments(fid, anchor).compose(TransformUtils.<SubCommentsBean>defaultSchedulers()).subscribe(new CommonSubscriber<SubCommentsBean>() {
            @Override
            public void onSuccess(SubCommentsBean response) {
                sub_comments_view.hideLoading();
                sub_comments_view.loadSubComments(response);
            }

            @Override
            public void onFailure(BaseBean response) {
                sub_comments_view.hideLoading();
                sub_comments_view.showError(response.getMsg());
            }
        });
    }
}
